<template>
  <el-form :model="form" label-width="auto" style="max-width: 600px">
    <el-form-item label="姓名">
      <el-input v-model="form.name" />
    </el-form-item>
    <el-form-item label="密码">
      <el-input v-model="form.password" />
    </el-form-item>
    <el-form-item label="年级">
      <el-select v-model="form.classInfo.id" >
        <el-option v-for="item in classInfoList" :value="item.id">{{item.name}}</el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="出生日期">
      <el-col :span="11">
        <el-date-picker
            v-model="form.birthday"
            type="date"
            placeholder="Pick a date"
            style="width: 100%"
        />
      </el-col>
    </el-form-item>
    <el-form-item label="年龄">
      <el-input v-model="form.age" />
    </el-form-item>
    <el-form-item label="性别">
      <el-radio-group v-model="form.gender">
        <el-radio value="男">男</el-radio>
        <el-radio value="女">女</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">Create</el-button>
      <el-button>Cancel</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import axios from "axios";

export default {
  name: "UserAdd"
  ,data(){
    return{
      form:{
        "name": "",
        "password": "",
        "gender": "",
        "birthday": "",
        "age": '',
        "classInfo": {
          "name": ""
        }
      }
      ,classInfoList:[]
    }
  }
  ,methods:{
    onSubmit(){
      console.log(this.form)
      // 向后台发送请求 提交 form表单的数据
      axios.post("http://localhost:8080/user2/add",this.form)
          .then(result=>{
            console.log(result)
          }).catch(error=>{
        console.log("失败了：" + error)
      })
    }
    ,findClassInfo(){
      axios.get("http://localhost:8080/class/findAll")
          .then(result=>{
            console.log(result.data)
            this.classInfoList = result.data
          })
    }
  }
  ,mounted() {
    this.findClassInfo()
  }
}
</script>


<style scoped>

</style>